/*
 * This file is part of the eccOS Library.
 * Copyright (C) 2007.
 *
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 */
package org.openeccos.internal;

import org.openeccos.model.MTask;
import org.openeccos.util.PDFormat;

import nextapp.echo2.app.Border;
import nextapp.echo2.app.Button;
import nextapp.echo2.app.Color;
import nextapp.echo2.app.Column;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.Font;
import nextapp.echo2.app.Insets;
import nextapp.echo2.app.Row;
import nextapp.echo2.app.event.ActionEvent;
import nextapp.echo2.app.event.ActionListener;
import echopointng.BalloonHelp;
import echopointng.ButtonEx;
import echopointng.ContainerEx;
import echopointng.LabelEx;
import echopointng.MutableBorderEx;

/**
 *
 *
 * @author cgspinner@web.de
 */
public class PDTaskEntry extends ContainerEx {

	private MTask task;
	private Button button;

	public PDTaskEntry(MTask t) {
		this.task = t;

		MutableBorderEx border = new MutableBorderEx(0, null, Border.STYLE_NONE);
		border.setBottom(2, Color.DARKGRAY, Border.STYLE_DOTTED);
		setBorder(border);

		Row row = new Row();
		add(row);

		BalloonHelp baoWorkflowOption = new BalloonHelp();
		baoWorkflowOption.setInsets(new Insets(9, 5, 0, 0));
		row.add(baoWorkflowOption);

		Column colWorkflowOption = new Column();
		// colWorkflowOption.setBackground(Color.YELLOW);
		baoWorkflowOption.setPopUp(colWorkflowOption);

		LabelEx lblAssignedBy = new LabelEx("Task assigned by: " + task.getCreatedBy());
		colWorkflowOption.add(lblAssignedBy);

		LabelEx lblAssignedSince = new LabelEx("Task assigned since: " + PDFormat.formatLong(task.getCreatedDate()));
		colWorkflowOption.add(lblAssignedSince);

		LabelEx lblPriority = new LabelEx("Priority: " + task.getPriority());
		colWorkflowOption.add(lblPriority);

		ButtonEx btnAcceptNow = new ButtonEx("Accept now");
		colWorkflowOption.add(btnAcceptNow);

		ButtonEx btnManiana = new ButtonEx("Remind me later");
		colWorkflowOption.add(btnManiana);

		ButtonEx btnDecline = new ButtonEx("Decline");
		colWorkflowOption.add(btnDecline);

		button = new Button(task.getName());
		button.setFont(new Font(Font.VERDANA, Font.BOLD, new Extent(13)));
		button.setForeground(Color.DARKGRAY);
		button.setHeight(new Extent(16));
		button.setInsets(new Insets(5, 0, 5, 0));
		button.setBorder(new Border(0, null, Border.STYLE_NONE));
		button.setRolloverEnabled(true);
		button.setRolloverForeground(Color.WHITE);
		button.setRolloverBackground(Color.LIGHTGRAY);
		button.setRolloverBorder(new Border(0, null, Border.STYLE_NONE));
		if (task.getPriority() > 4) {
			button.setForeground(Color.RED);
		} else if (task.getPriority() > 3) {
			button.setForeground(Color.ORANGE);
		}
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				task.executeTask();
			}
		});
		row.add(button);

		LabelEx lblDescription = new LabelEx();
		String s = task.getDescription();
		if (task.getStatus() == MTask.STATUS_ACCEPTED_AND_WAITING_FOR_ANSWER) {
			s += " (waiting...)";
		}
		lblDescription.setText(s);
		lblDescription.setFont(new Font(Font.VERDANA, Font.PLAIN, new Extent(8)));
		lblDescription.setForeground(Color.DARKGRAY);
		lblDescription.setInsets(new Insets(20, 0, 0, 2));
		add(lblDescription);
	}

	public MTask getTask() {
		return task;
	}

	public Button getButton() {
		return button;
	}

}
